package com.xdhl.fu.fi.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xdhl.fu.common.core.web.controller.BaseController;
import com.xdhl.fu.common.core.web.domain.AjaxResult;
import com.xdhl.fu.common.core.web.page.TableDataInfo;
import com.xdhl.fu.common.log.annotation.Log;
import com.xdhl.fu.common.log.enums.BusinessType;
import com.xdhl.fu.common.security.annotation.RequiresPermissions;
import com.xdhl.fu.fi.service.IFlightScheduleService;
import com.xdhl.fu.flight.info.api.domain.FlightSchedule;
import com.xdhl.fu.flight.info.api.domain.vo.FlightScheduleVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * 航班排班Controller
 *
 * @author 朱力维
 * @date 2022-06-24
 */
@RestController
@RequestMapping("/schedule")
public class FlightScheduleController extends BaseController {

    @Resource
    private IFlightScheduleService flightScheduleService;

    /**
     * 查询航班排班列表
     */
    @RequiresPermissions("flight:schedule:list")
    @GetMapping("/list")
    public TableDataInfo list(FlightScheduleVO flightSchedule) {
        startPage();
        LambdaQueryWrapper<FlightSchedule> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(null != flightSchedule.getStartDate(), FlightSchedule::getStartDate, flightSchedule.getStartDate());
        wrapper.eq(null != flightSchedule.getEndDate(), FlightSchedule::getEndDate, flightSchedule.getEndDate());
        List<FlightSchedule> list = flightScheduleService.list(wrapper);
        return getDataTable(list);
    }

    /**
     * 获取航班排班详细信息
     */
    @RequiresPermissions("flight:schedule:query")
    @GetMapping(value = "/{dataId}")
    public AjaxResult getInfo(@PathVariable("dataId") String dataId) {
        return AjaxResult.success(flightScheduleService.getById(dataId));
    }

    /**
     * 新增航班排班
     */
    @RequiresPermissions("flight:schedule:add")
    @Log(title = "航班排班", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FlightScheduleVO flightSchedule) {
        return toAjax(flightScheduleService.save(flightSchedule));
    }

    /**
     * 修改航班排班
     */
    @RequiresPermissions("flight:schedule:edit")
    @Log(title = "航班排班", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FlightScheduleVO flightSchedule) {
        return toAjax(flightScheduleService.updateById(flightSchedule));
    }

    /**
     * 删除航班排班
     */
    @RequiresPermissions("flight:schedule:remove")
    @Log(title = "航班排班", businessType = BusinessType.DELETE)
    @DeleteMapping("/{dataIds}")
    public AjaxResult remove(@PathVariable String[] dataIds) {
        return toAjax(flightScheduleService.removeByIds(Arrays.asList(dataIds)));
    }

}
